package com.zykj.evaluation.ui.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.ComposeView
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.fragment.findNavController
import com.zykj.evaluation.R
import com.zykj.evaluation.ui.theme.EvaluationTheme
import com.zykj.evaluation.viewmodel.HomeViewModel
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class HomeFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = ComposeView(inflater.context).apply {
        layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        setContent {
            CompositionLocalProvider(
                LocalBackPressedDispatcher provides requireActivity().onBackPressedDispatcher
            ) {
                EvaluationTheme {
                    val homeViewModel = viewModel<HomeViewModel>()
                    Home(homeViewModel = homeViewModel, onStartAnswer = {
                        val bundle = bundleOf(
                            "pageId" to it.testPagerId,
                            "serialNum" to it.serialNum,
                            "taskId" to it.id,
                            "configAddress" to it.address,
                            "examId" to it.examId
                        )
                        findNavController().navigate(R.id.nav_answer_sheet, bundle)
                    })
                }
            }
        }
    }

}